#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os


def check_path(task_file):
    index = task_file.rfind("/")
    if index == -1:
        index = task_file.rfind("\\")
        if index == -1:
            return
    path = task_file[:index]
    if not os.path.exists(path):
        os.makedirs(path)


def write_record(rec_file, content):
    with open(rec_file, 'a', encoding='utf-8') as fp:
        fp.write('{0}\n'.format(content))


def load_record(rec_file):
    deal_set = set()
    with open(rec_file, encoding='utf-8') as fp:
        for line in fp:
            try:
                infos = line.strip().split('\t')
                if len(infos[0]) != 0:
                    deal_set.add(infos[0])
            except Exception as e:
                print(e)
    return deal_set


def load_path_files(path):
    file_list = []
    for dir_path, sub_dirs, sub_files in os.walk(path):
        for subfile in sub_files:
            full_file = os.path.join(dir_path, subfile)
            file_list.append(full_file)
    return file_list
